<?php
/**
 * 充值收款记录
 * User: guojing
 * Date: 2020/4/10
 * Time: 0:03
 */

namespace app\api\model;

use app\common\model\SystemReceiveAccount;
use think\Db;
use think\Model;

class RechargeOffline extends Model
{

    protected $name = 'recharge_offline';

    /**
     *  返回收款方
     */
    public static function receiveBank()
    {
        //获取系统的收款账户
        $receiveBank = SystemReceiveAccount::findInfoByCondition(['id' => 1]);
        return [
            'receive_bank_name' => $receiveBank && isset($receiveBank['receive_bank_name']) && $receiveBank['receive_bank_name'] ? $receiveBank['receive_bank_name'] : '',
            'receive_uname' => $receiveBank && isset($receiveBank['receive_uname']) && $receiveBank['receive_uname'] ? $receiveBank['receive_uname'] : '',
            'receive_bank_no' => $receiveBank && isset($receiveBank['receive_bank_no']) && $receiveBank['receive_bank_no'] ? $receiveBank['receive_bank_no'] : '',
            'receive_bank_number' => $receiveBank && isset($receiveBank['receive_bank_number']) && $receiveBank['receive_bank_number'] ? $receiveBank['receive_bank_number'] : ''
        ];
    }

    /**
     * 获取列表
     */
    public static function dataList($params = [])
    {
        $where = [];
        $page = '1, 20';
        if (isset($params['page']) && $params['page_size']) {
            $page = $params['page'] . ',' . $params['page_size'];
        }
        if (isset($params['uid'])) {
            $where['send_uid'] = $params['uid'];
        }
        $list = self::where($where)->page($page)->select();
        return $list ? $list : [];
    }

    public static function addRecord($addData = [])
    {
        $data = $addData;
        $data['createtime'] = time();
        $data['updatetime'] = time();
        return self::create($data);
    }

    public static function sumRechargePrice($condition = [])
    {
        return self::where($condition)->sum('amount');
    }

}